// Simple2PC.Test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#ifdef WINDOWS
#include <Simple2PC.Core/WSAHelper.h>
#endif


#include <Simple2PC.Core/Config.h>
#include <Simple2PC.Core/TransactionManager.h>
#include <Simple2PC.Core/TransactionStoreServer.h>
#include <Simple2PC.Core/AccountServer.h>
#include <Simple2PC.Core/Client.h>

int main(int argc, char *argv[])
{
#ifdef WINDOWS
	StartWSA();
#endif


	if(2 != argc)
	{
		printf("usage: exe [setting file path]\n");
		return -1;
	}
	
	PC2::ApplicationSettings lSettings;

	PC2::Config::GetApplicationSettings(argv[1], &lSettings);

	if("manager" == lSettings.m_Type)
	{
		PC2::TransactionManager lManager(&lSettings);
		
		lManager.Exec();
	}
	else if("account" == lSettings.m_Type)
	{
		PC2::AccountServer lAccount(&lSettings);
		
		lAccount.Exec();
	}
	else if("transaction" == lSettings.m_Type)
	{
		PC2::TransactionStoreServer lTranscation(&lSettings);
		lTranscation.Exec();
	}
	else if("client" == lSettings.m_Type)
	{
		PC2::Client lClient(&lSettings);

		lClient.Run();
	}

#ifdef WINDOWS
	StopWSA();
#endif
	return 0;
}

